<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调</title>

    <!-- 引入vue + axios + common.js -->
    <!-- 导入vue -->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <!-- 导入axios -->
    <script src="js/plugins/axios/dist/axios.js"></script>
    <!-- 导入全局属性和基础路径 -->
    <script src="js/common.js"></script>
</head>
<body>
<div id="myDiv">

</div>
<script type="text/javascript">
    new Vue({
        el:"#myDiv",
        mounted(){
            //解析参数对象
            let url = location.href;
            let paramObj = parseUrlParams2Obj(url);

            //获取发送请求参数
            let params = {"code":paramObj.code};
            //发起微信登录请求  调用微信登录接口
            this.$http.post("/login/wechat",params)
                .then(result=>{
                    result = result.data;
                    if(result.success){ //已经关联了 免密登录之后，需要调到主页
                        //做登录
                        //提示
                        alert("登录成功！")
                        //1.保存返回的token，logininfo到localStorage
                        let {token,logininfo} = result.obj;
                        localStorage.setItem("token",token);
                        localStorage.setItem("logininfo",JSON.stringify(logininfo));
                        //2.跳转到首页，显示当前登录人
                        location.href="/index.html";
                    }else{ //没有关联跳转绑定页面   ?access_token=access_token&openid=openid
                        let binderUrl = "http://bugtracker.itsource.cn/binder.html"+result.obj;
                        location.href = binderUrl;
                    }
                })
                .catch(result=>{
                    alert("系统错误");
                    console.log(result);
                })
        }
    });
</script>
</body>
</html>